package com.wondertek.poms.log.consumer;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.wondertek.poms.common.constant.Constants;
import com.wondertek.poms.core.service.IPcOperateLogService;
import com.wondertek.poms.dao.po.PcOperateLog;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@RabbitListener(queues = Constants.LOG_QUEUE)
public class LogConsumer {
	@Autowired
	private IPcOperateLogService logService;
	
	@RabbitHandler
    public void receiveContentTopic(String message) {
    	log.info("mq消息：" + message);
    	try {
    		PcOperateLog ol = JSON.parseObject(message, PcOperateLog.class);
			logService.save(ol);
		} catch (Exception e) {
			log.error("保存日志失败，日志：{}，异常：{}", log, e);
		}
    }
}
